var imgPath = "img/menu/";
var selectedLevel = "3";// 当前被选择的菜单层级

$("#smoothmenu1 a[level='1']").mouseover(function(){
	$(this).css("background","url('" + imgPath + "menu_over.jpg')");						
	$(this).css("color","black");
});

$("#smoothmenu1 a[level='1']").mouseout(function(){
	if($(this).attr("selected") == "true") {
		return;
	}
	$(this).css("background","url('" + imgPath + "menu_normal.jpg')");						
	$(this).css("color","white");
});

$("#smoothmenu1 a[level='2']").mouseover(function(){
	$(this).css("background","url('" + imgPath + "submenu_over.jpg')");	
	$(this).css("color","black");
});

$("#smoothmenu1 a[level='2']").mouseout(function(){
	if($(this).attr("selected") == "true") {
		return;
	}
	$(this).css("background","url('" + imgPath + "submenu_normal.jpg')");						
	$(this).css("color","white");
});

/**
 * 点击菜单
 */
function clickMenuItem() {
	var obj = event.srcElement;
	var level = obj.level;
	if(level == "1") {
		clickMenuLevel1();
	}else if(level == "2") {
		clickMenuLevel2();
	}else {
		clickMenuOthers();
	}
}

/**
 * 点击第一级菜单
 */
function clickMenuLevel1(){
	var obj = event.srcElement;
	if(obj.index == 8){
		startupLocalExe();
	}
	var level = obj.level;
	var isListType = obj.type == "0"; // 是否是列表菜单
	var hasChild = ("true" == obj.hasChild);
	var isTop = (obj.position == "0");
	if(hasChild && isTop) {
		return;
	}
	
	
	$("#smoothmenu1 a[level='1']").css("background","url('" + imgPath + "menu_normal.jpg')");
	$("#smoothmenu1 a[level='1']").css("color","white");
	$("#smoothmenu1 a[level='1']").attr("selected","false");
	
	$("#smoothmenu1 a[level='2']").css("background","url('" + imgPath + "submenu_normal.jpg')");
	$("#smoothmenu1 a[level='2']").attr("selected","false");
	$("#smoothmenu1 a[level='2']").css("color","white");
	
	$(obj).css("background","url('" + imgPath + "menu_over.jpg')");
	$(obj).css("color", "black");
	$(obj).attr("selected","true");
	
	if(isListType){ // 列表菜单
		if(!isTop && hasChild) {// 顶部点击后显示左侧子菜单
			showLeftAll(true);
			menu_left.location.href = "menu_left.jsp?itemIndex=" + obj.index + "&type=0";
			main.location.href = "welcomePage.htm";
		}else {
			if(obj.src != "") {
				showLeftAll(false);
				main.location.href = obj.src;
				selectedLevel = level;
			}
		}
	}else {// 树形菜单
		menu_left.location.href = "menu_left.jsp?itemIndex=" + obj.index + "&type=1";
		main.location.href = "welcomePage.htm";
	}
	
}

/**
 * 点击第二级菜单
 */
function clickMenuLevel2(){
	var obj = event.srcElement;
	var level = obj.level;
	var hasChild = ("true" == obj.hasChild);
	var isTop = (obj.position == "0");
	
	var pobjs = $("#smoothmenu1 a[level='1']");
	pobjs.css("background","url('" + imgPath + "menu_normal.jpg')");
	pobjs.css("color","white");
	pobjs.attr("selected","false");
	var pObj = $(obj).offsetParent().offsetParent().offsetParent().children(0);
	pObj.css("background","url('" + imgPath + "menu_over.jpg')");
	pObj.css("color","black");
	pObj.attr("selected","true");
	
	if(!isTop) {// 左侧2级菜单
		var objs = $("#menu_left a[level='2']");
		objs.css("color", "#f89342");
		objs.css("font-weight","normal");
		
		$(obj).css("color", "#f87d19");
		$(obj).css("font-weight","bold");
	} else {// 顶部2级菜单
		var objs = $("#smoothmenu1 a[level='2']");
		objs.css("background","url('" + imgPath + "submenu_normal.jpg')");
		objs.css("color","white");
		objs.attr("selected","false");
		$(obj).css("background","url('" + imgPath + "submenu_over.jpg')");
		$(obj).css("color","black");
		$(obj).attr("selected","true");
	}
	
	if(hasChild) {
		showLeftAll(true);
		menu_left.location.href = "menu_left.jsp?itemIndex=" + obj.index;
		//main.location.href = "welcomePage.htm";
		main.location.href = obj.childSrc;
		selectedLevel = level;
	}else {
		//showLeftAll(false);
		if(obj.src != "") {
			parent.main.location.href = obj.src;
			selectedLevel = level;
		}
	}
}

/**
 * 点击第三级及其三级以下菜单
 */
function clickMenuOthers(){
	var obj = event.srcElement;
	var hasChild = ("true" == obj.hasChild);
	var isTop = (obj.position == "0");
	if(hasChild && isTop) {
		return;
	}
	
	//$("#menu_left a[level='3']").css("color", "#f89342");
	//$("#menu_left a[level='3']").css("font-weight","normal");
	$("#menu_left a[level!='1'][level!='2']").css("color", "#f89342");
	$("#menu_left a[level!='1'][level!='2']").css("font-weight","normal");
	
	setSelected(obj);
	var href = obj.src;
	if(href != "") {
		parent.main.location.href = href;
		selectedLevel = obj.level;
	}
}


function setSelected(obj) {
	if(!obj){
		return;
	}
	
	$(obj).css("color", "#f87d19");
	$(obj).css("font-weight","bold");
	
	setSelected(document.getElementById(obj.pindex));
}
/**
 * 顶部收缩
 */
function hideTop(){
	var obj = event.srcElement; 
	var flag= obj.flag;
	var topper = document.getElementById("topper");
	if(flag == "1") {
		obj.src = "img/common/top_hide2.gif";
		obj.flag = "2";
		topper.style.display = "none";
	}else {
		obj.src = "img/common/top_hide1.gif";
		obj.flag = "1";
		topper.style.display = "";
	}
}

/**
 * 显示或隐藏左侧
 */
function hideLeft() {
	var obj = event.srcElement; 
	var flag= obj.flag;
	var menu_left_div = document.getElementById("menu_left_div");
	if(flag == "1") {
		obj.src = "img/common/left_hide2.gif";
		obj.flag = "2";
		menu_left_div.style.display = "none";
	}else {
		obj.src = "img/common/left_hide1.gif";
		obj.flag = "1";
		menu_left_div.style.display = "";
	}
}

/**
 * 显示或隐藏左侧，包括菜单和控制按钮
 */
function showLeftAll(isShow) {
	var menuObj = document.getElementById("menu_left_div");
	if(!menuObj) {
		return;
	}
	var hideBtn = document.getElementById("menu_left_hide_btn");
	if(isShow) {
		menuObj.style.display = "";
		hideBtn.style.display = "";
	}else {
		menuObj.style.display = "none";
		hideBtn.style.display = "none";
	}
}

/**
 * 树节点点击事件
 */
function clickTreeNode(nodeObj){
	var href = nodeObj.getArgValue("href");
	if(href == '' || href == undefined){
		return;
	}
	parent.main.location.href = href;
}

